package zhh.tangbao.commodity.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import zhh.tangbao.commodity.entity.CommodityEntity;
import zhh.tangbao.commodity.entity.CommodityMachineEntity;
import zhh.tangbao.commodity.vo.MachineOptionsVo;
import zhh.tangbao.wechat.dto.WeChatMachineQueryDto;
import zhh.tangbao.wechat.vo.WeChatCommodityMachineVo;

import java.util.Collection;
import java.util.List;

/**
 * <p>
 *     描述
 * </p>
 * @author 粥灰灰
 * <p>2023/3/2</p>
 */

@Repository
@Mapper
public interface CommodityMachineEntityDao extends BaseMapper<CommodityMachineEntity> {

    List<WeChatCommodityMachineVo> wechatMachinePage(WeChatMachineQueryDto dto);

    @Update("UPDATE commodity_machine_entity SET running_state = #{runningState} WHERE id = #{machineId} AND data_status = 1")
    int updateMachineRunningState(@Param("machineId") String machineId, @Param("runningState") Integer runningState);

    int insertBatchSomeColumn(Collection<CommodityMachineEntity> commodityMachineEntities);

    @Update("UPDATE commodity_machine_entity SET activation_status = #{activationStatus}, activation_time = NOW() WHERE id = #{id}")
    int updateMachineActivationInfo(@Param("id") String id, @Param("activationStatus") Integer activationStatus);

    @Select("SELECT id stringKey, machine_name label FROM commodity_machine_entity")
    List<MachineOptionsVo> machineToOptions();
}
